//vector的遍历
//摆平积木
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n = 0;
	
	while(cin >> n && n != 0)
	{
		vector<int> v(n,0);
		int sum=0;
		for(int i = 0; i < v.size(); i++)
		{
			cin >> v[i];
			sum += v[i];
		}
		int ave = sum/n;
		int ans = 0;
		for(int i = 0; i < v.size(); i++)
		{
			if(v[i] > ave) ans += v[i] - ave;
		}
		cout << ans << endl;
		cout << endl;
	}
	return 0;
}
